package com.jianjun.ktui.ui.data


import com.jianjun.ktui.Method
import com.jianjun.ktui.httpRuoYi
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch

/**
 *
 * @author source
 * {@code @date} 2025/3/24 09:55
 */
@Suppress("UNCHECKED_CAST")
object UserStore {
    var captchaKey: String = ""
    var token: String = ""
    var id: String = ""
    var name: String = ""
    var avatar: String = ""
    var roles: MutableList<String> = mutableListOf()
    var permissions: MutableList<String> = mutableListOf()
    private val dict: MutableMap<String, MutableList<MutableMap<String, Any>>> = mutableMapOf()


    @OptIn(DelicateCoroutinesApi::class)

    fun getDict(typeName: String): MutableList<MutableMap<String, Any>> {
        if (dict.contains(typeName)) {
            return dict[typeName]!!
        } else {
            GlobalScope.launch {
                val resMap: MutableMap<String, Any> =
                    httpRuoYi("/system/dict/data/type/$typeName", mutableMapOf(), Method.GET)

                dict[typeName] = resMap["data"] as MutableList<MutableMap<String, Any>>
            }
            return mutableListOf()
        }
    }
}
